package com.moleq.service;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.moleq.db.DatabaseHelper;
import com.moleq.db.DatabaseSchema;
import com.moleq.models.CustomerSetting;
import com.moleq.models.GlobalInfo;
import com.moleq.models.StoreSetting;

public class StoreService {
	private DatabaseHelper DBHelper;
	private Context mContext;
	
	public StoreService() {
		
	}
	public StoreService(Context context){
		mContext = context;
		this.DBHelper = new DatabaseHelper(GlobalInfo.getInstance().ShareContext);
	}
	
	public List<StoreSetting> getStoreSetting(){
		List<StoreSetting> list = new ArrayList<StoreSetting>();
		SQLiteDatabase db = DBHelper.getWritableDatabase();
		String sql = "select * from t_store_setting";
		Cursor cursor = db.rawQuery(sql, null);
//		Cursor cursor = dbHelper.select(sql);
		if(cursor == null) return null;
		if(cursor.moveToNext()){
			StoreSetting item = new StoreSetting();
			item.setSs_id(cursor.getInt(cursor.getColumnIndex(DatabaseSchema.StoreSetting.SS_ID)));
			item.setSs_name(cursor.getString(cursor.getColumnIndex(DatabaseSchema.StoreSetting.SS_NAME)));
			item.setSs_other_name(cursor.getString(cursor.getColumnIndex(DatabaseSchema.StoreSetting.SS_OTHER_NAME)));
			item.setSs_address_1(cursor.getString(cursor.getColumnIndex(DatabaseSchema.StoreSetting.SS_ADDRESS_1)));
			item.setSs_address_2(cursor.getString(cursor.getColumnIndex(DatabaseSchema.StoreSetting.SS_ADDRESS_2)));
			item.setSs_city(cursor.getString(cursor.getColumnIndex(DatabaseSchema.StoreSetting.SS_CITY)));
			item.setSs_state(cursor.getString(cursor.getColumnIndex(DatabaseSchema.StoreSetting.SS_STATE)));
			item.setSs_zip(cursor.getString(cursor.getColumnIndex(DatabaseSchema.StoreSetting.SS_ZIP)));
			item.setSs_telephone(cursor.getString(cursor.getColumnIndex(DatabaseSchema.StoreSetting.SS_TELEPHONE)));
			item.setSs_fax(cursor.getString(cursor.getColumnIndex(DatabaseSchema.StoreSetting.SS_FAX)));
			item.setSs_website(cursor.getString(cursor.getColumnIndex(DatabaseSchema.StoreSetting.SS_WEBSITE)));
			item.setSs_business_name(cursor.getString(cursor.getColumnIndex(DatabaseSchema.StoreSetting.SS_BUSINESS_NAME)));
			list.add(item);
		}
		cursor.close();
		return list;
	}
	public String AddStoreSetting(String sql){
//		String error = dbHelper.sqlExecute(sql);
		String error = DBHelper.execSQL(sql);
		return error;
	}
	public String UpdateStoreSetting(String sql){
//		String error = dbHelper.sqlExecute(sql);
		String error = DBHelper.execSQL(sql);
		return error;
	}
}
